﻿'use strict';
document.oncontextmenu = new Function("return false;");
var appInstance = window.parent.appInstance;
//load script
var scripts = new Array();
scripts.push("utils/common.js");
scripts.push("utils/global.js");
scripts.push("utils/request.js");
scripts.push("utils/service.js");
//external lib
scripts.push("lib/jquery.js");
scripts.push("lib/vue.js");
scripts.push("lib/element.js");
//model
scripts.push("model/Dictionary.js");
//widget
scripts.push("widget/TabMenuView.js");
scripts.push("widget/TreeView.js");
scripts.push("widget/DataGridView.js");

//load style table
var style_table = new Array();
style_table.push("page.css");
style_table.push("view.css");
style_table.push("element.css");

/**
*mark script function 
*/
var launcherScripts = new Array();
function markscript(scriptName){
    console.log("loaded script:"+scriptName);
    launcherScripts.push(scriptName);
}
function isAllScriptLoaded(){
    return launcherScripts.length == allScripts.length;
}
/**
*load script function 
*/
function loadscript(oHead,url) {    
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.src = url;
    oHead.appendChild(oScript);
}
/**
*load style function 
*/
function loadstyle(oHead,url) {   
    var oStyle = document.createElement("link");
    oStyle.rel = "stylesheet";
    oStyle.type = "text/css";
    oStyle.href = url;
    oHead.appendChild(oStyle);
}

function newMeta(httpEquiv,content){
    var meta = document.createElement("meta");
    meta["http-equiv"] = httpEquiv;
    meta["content"] = content;
    return meta;
}
/**
 * initDocument
 * @returns head
 */
function initDocument(){
    var oHead = document.getElementsByTagName('HEAD').item(0);   
    oHead.appendChild(newMeta("Content-Type","text/html; charset=utf-8"));
    oHead.appendChild(newMeta("X-UA-Compatible","IE=edge"));
    return oHead;  
}
/**
*start page
*/
function startPage() {    
    var oHead = initDocument();    
    //lanucher style
    var stylesPath = "../stylesheets/";  
    style_table.forEach(function(item){
        loadstyle(oHead,stylesPath.concat(item));
    }); 
    //lanucher script
    var scriptPath = "../javascript/";  
    launcherScripts.length = 0;
    scripts.forEach(function(item){
        loadscript(oHead,scriptPath.concat(item));
    });
    return appInstance.router;
}

function openDialogPage(path,title,w,h) { 
    var pageUrl = appInstance.mAppConfig.buildChildDataPageUrl(path);
    appInstance.router.openDialogPage(title, pageUrl, w, h, "./stylesheets/ico/info.png");
}

